package com.sevennotes.classtable.ui.pages.student_history

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Share
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sevennotes.classtable.config.Config
import com.sevennotes.classtable.model.ClassRecord
import com.sevennotes.classtable.model.ClassRecordWithName
import com.sevennotes.classtable.ui.pages.TitleText
import com.sevennotes.classtable.ui.pages.components.ItemCell
import com.sevennotes.classtable.ui.pages.components.RecordCell
import com.sevennotes.classtable.ui.pages.components.SimpleComfirmDialog
import com.sevennotes.classtable.ui.pages.main_screen.MainScreenPad
import com.sevennotes.classtable.ui.pages.main_screen.StudentHistoryState
import com.sevennotes.classtable.utils.TimeUtil

@Composable
fun StudentHistoryPage(
  studentName: String,
  state: StudentHistoryState,
) {
  LazyColumn {
    item {
      ItemCell {
        Text(text = "$studentName 共有记录数${state.historyList.size}条")
      }
    }
    items(state.historyList) {
      StudentHistoryRecordCell(it)
    }
  }
}

@Composable
fun StudentHistoryRecordCell(record: ClassRecord) {
  ItemCell {
    Text(
      modifier = Modifier.weight(1f),
      fontSize = 18.sp,
      text = record.startTime.let {
        TimeUtil.formatDate(
          it,
          "MM月dd日 HH : mm"
        )
      } + "       ${record.duration} 分钟")
    val isPositive = record.gpChange >= 0
    Text(
      fontWeight = FontWeight.Bold,
      fontSize = 20.sp,
      text = if (isPositive) "+${record.gpChange}分" else "${record.gpChange}分",
      color = if (isPositive) Config.right else Config.wrong,
    )
  }
}

@Preview
@Composable
fun StudentHistoryRecordCellPreview() {
  StudentHistoryRecordCell(record = ClassRecord())
}


@Preview(showBackground = true)
@Composable
fun StudentHistoryPagePreview() {
  StudentHistoryPage(
    studentName = "张三", state = StudentHistoryState(
      historyList = listOf(
        ClassRecord()
      )
    )
  )
}